package com.tengju.settlement.infrastructure.repository;

import com.tengju.settlement.domain.model.account.FrozenDetailRepository;
import com.tengju.settlement.domain.model.account.FrozenStatus;
import com.tengju.settlement.domain.model.account.UserIdCode;
import com.tengju.settlement.infrastructure.persistence.mybatis.mapper.tengju.custom.FrozenDetailMapper;
import com.tengju.settlement.infrastructure.shared.InfraException;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class FrozenDetailRepositoryImpl implements FrozenDetailRepository {

    @Resource
    private FrozenDetailMapper frozenDetailMapper;

    @Override
    public void updateStatusByCycleAddIdBizCode(FrozenStatus frozenStatus, UserIdCode updateBy, Integer cycleAddId, String bizCode) {
        int count = frozenDetailMapper.updateStatusByCycleAddIdBizCode(frozenStatus.getVal(),
                updateBy.getValue() + "", cycleAddId, bizCode);
        if (count != 1) {
            throw new InfraException("变更冻结状态失败");
        }
    }

    @Override
    public void updateStatusByBizIdBizCode(FrozenStatus frozenStatus, UserIdCode updateBy, Integer bizId, String bizCode) {
        int count = frozenDetailMapper.updateStatusByBizIdBizCode(frozenStatus.getVal(),
                updateBy.getValue() + "", bizId, bizCode);
        if (count != 1) {
            throw new InfraException("变更冻结状态失败");
        }

    }
}
